package com.gombe.credit.app.ui.activity

import android.view.View
import com.gombe.credit.app.R
import com.gombe.credit.app.common.CommonActivity
import com.gombe.credit.app.databinding.ActGombeCreditUserAdviceTypePageBinding
import com.gombe.credit.app.event.GombeCreditEventPointType
import com.gombe.credit.app.utils.GombeCreditTitleBarUtil
import com.gombe.credit.app.utils.helper.GombeCreditConfigsHelper
import com.gombe.credit.lib.adapter.GombeCreditOnSingleClickListener
import java.util.Calendar

/**
 * 建议类型
 */
class ActGombeCreditUserAdviceType: CommonActivity() {
    lateinit var binding: ActGombeCreditUserAdviceTypePageBinding

    override fun takeGombeCreditRootView(): View {
        binding = ActGombeCreditUserAdviceTypePageBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initGombeCreditView() {
        setGombeCreditTitleBarVisibility(View.VISIBLE)
        setGombeCreditTextTitle(getString(R.string.gombe_credit_string_customer_dialog_feedback))
        setGombeCreditTextTitleColor(getColor(R.color.black))
        setGombeCreditRightBtnRes(R.mipmap.gombe_credit_image_customer_black_icon)
        setGombeCreditBackBtnRes(R.mipmap.gombe_credit_image_back_black_icon)
        setGombeCreditRootParentBackgroundColor(getColor(R.color.white))
        GombeCreditTitleBarUtil.setStatusBarLightMode(this, true)
    }

    override fun initGombeCreditListener() {
        //联系客服
        rootViewBinding.rootCustomer.setOnClickListener(object : GombeCreditOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                showCustomerDialog("Advice Type Page")
                addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_CLICK.CUSTOMER,"Advice Type Page")
            }
        })
        //意见反馈
        binding.feedbackLayout.setOnClickListener(object : GombeCreditOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                onIntent(ActGombeCreditUserFeedback::class.java)
            }
        })
        //在线客服
        binding.onlineLayout.setOnClickListener(object : GombeCreditOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                onIntent(ActGombeCreditUserChat::class.java)
            }
        })
    }

    override fun takeGombeCreditData() {
        val hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
        when (hour) {
            in 0..11 -> {
                binding.textHello.text = getString(R.string.gombe_credit_advice_type_morning)
            }
            in 12..17 -> {
                binding.textHello.text = getString(R.string.gombe_credit_advice_type_afternoon)
            }
            else -> {
                binding.textHello.text = getString(R.string.gombe_credit_advice_type_evening)
            }
        }

        //是否显示在线客服入口
        val isShowCustomerChat = GombeCreditConfigsHelper.isShowCustomerChat()
        if (isShowCustomerChat){
            binding.onlineLayout.visibility = View.VISIBLE
        } else {
            binding.onlineLayout.visibility = View.GONE
        }
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_PAGE.USER_ADVICE_TYPE_START)
    }

    override fun onDestroy() {
        super.onDestroy()
        addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_PAGE.USER_ADVICE_TYPE_END)
    }
}